<!DOCTYPE html>
<html lang="zh">
  <head>
    <meta charset="utf-8">

    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title></title>
  </head>
  <body>
    序号:<input type="text"  id="xh" disabled><br>
    书名:<input type="text"  id="sm"><br>
    作者:<input type="text"  id="zz"><br>
    出版社:<input type="text"  id="cbx"><br>
    价格 :<input type="text"  id="jg"><br>
    <button onclick="tjxg()">提交修改</button>
  </body>
    <script src="axios.min.js"></script>
  <script>
    window.onload=function(){
    var id =  GetQueryString("n");
       var xh = document.getElementById('xh');
       var sm = document.getElementById('sm');
       var zz = document.getElementById('zz');
      var cbx = document.getElementById('cbx');
       var jg = document.getElementById('jg');
    var url = "http://localhost:8080/system/book/select/"+id;
     axios.get(url,"",{

     }).then(response => {
       if(response.data.code == 200){
         console.log(response);
          xh.value = response.data.data.id;
           sm.value = response.data.data.bookName;
            zz.value = response.data.data.authorName;
             cbx.value = response.data.data.press;
              jg.value = response.data.data.price;
       }else{
          console.log(response);
          alert(response.data.message)
       }
       })

    }

   function tjxg(){


         var xh = document.getElementById('xh').value;
         var sm = document.getElementById('sm').value;
         var zz = document.getElementById('zz').value;
        var cbx = document.getElementById('cbx').value;
         var jg = document.getElementById('jg').value;
         var token = localStorage.getItem('token');
         var url = "http://localhost:8080/system/book/update";

         const data = {
           id: xh,
           bookName: sm,
           authorName: zz,
           press: cbx,
           price: jg,
         }
          axios.post(url,data,{
             Headers: {
               'Content-Type':'application/json;charset=UTF-8',
             }
          }).then(response => {
            if(response.data.code == 200){
                  alert(response.data.message);
                  window.location.href = "index.html";

            }else{
               console.log(response);
               alert(response.data.message)
            }
            })

    }

    function GetQueryString(name){
        var reg = new RegExp("(^|&)"+name+"=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if(r!=null)
            return  unescape(r[2]);
        return null;
}

  </script>
</html>
